<%--
    Document   : view
    Created on : 05/07/2010, 22:40:42
    Author     : junior
--%>
<%@page import="br.com.pegasi.util.Arquivo"%>
<%@page import="java.io.*" %>
<%@page import="net.sf.jasperreports.engine.*,net.sf.jasperreports.engine.export.*, java.util.*"%>
<%
        javax.naming.InitialContext ctx = new javax.naming.InitialContext();
        javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("java:comp/env/jdbc/dbo_MicrosoftSQLServer");
        java.sql.Connection con = ds.getConnection();

        String relatorio = request.getParameter("relatorio") ;
        String jasperfile = application.getRealPath("/WEB-INF/relatorios/")+ "//"+relatorio+".jasper";
        String reportfile = application.getRealPath("relatorios")+ "//"+relatorio+".html";

        HashMap map = new HashMap();

        Enumeration itens = request.getParameterNames();
        while (itens.hasMoreElements()){
            Object key = itens.nextElement();
            map.put(key, request.getParameter(key.toString()));
        }
        
        
        JasperRunManager.runReportToHtmlFile(jasperfile ,reportfile , map, con);

        File arq = new File(reportfile);
        byte[] b = Arquivo.getByteFile(arq);

        response.setHeader("Cache-Control", "max-age=30");
        response.setHeader("Pragma", "No-cache");
        response.setDateHeader("Expires", 0);
        response.setContentLength(b.length);


        ServletOutputStream otp = response.getOutputStream();

        otp.write(b, 0, b.length);
        
         
        otp.flush();
        otp.close();
%>


